﻿@model GridModel<ActivityLogTypeModel>
@using Telerik.Web.Mvc;
@using Telerik.Web.Mvc.UI;
@{  
    //page title
    ViewBag.Title = T("Admin.Configuration.ActivityLog.ActivityLogType").Text;
}
@using (Html.BeginForm("SaveTypes", "ActivityLog"))
{
    <div class="section-header">
        <div class="title">
            <i class="fa fa-fire"></i>
            @T("Admin.Configuration.ActivityLog.ActivityLogType")
        </div>
        <div class="options">
            <button type="submit" name="save" value="save" class="btn btn-primary">
                <i class="fa fa-check"></i>
                <span>@T("Admin.Common.Save")</span>
            </button>
        </div>
    </div>
	<div>
		@(Html.Telerik().Grid<ActivityLogTypeModel>()
				.Name("activityLogType-grid")
				.BindTo(Model.Data)
						.Columns(columns =>
						{
							columns.Bound(x => x.Enabled)
								.Centered()
								.Template(x => Html.CheckBox("checkBox_" + x.Id.ToString(), x.Enabled, new { id = x.Id, @class = "checkboxGroups" }))
								.Title("<input id='mastercheckbox' type='checkbox'/>")
								.HtmlAttributes(new { style = "text-align:center" })
								.HeaderHtmlAttributes(new { style = "text-align:center" })
								.Width(50);
							columns.Bound(x => x.Name)
								.Width("97%");
						})
				.Footer(false)
		)
	</div>
    <script type="text/javascript">

        $(document).ready(function () {

            updateMasterCheckbox();

            $('#mastercheckbox').click(function () {
                $('.checkboxGroups').attr('checked', $(this).is(':checked')).change();
            });

            //wire up checkboxes. 
            $(document).on('change', '#activityLogType-grid input[type=checkbox][id!=mastercheckbox]', function (e) {
                updateMasterCheckbox();
            });
        });

        function updateMasterCheckbox() {
            var numChkBoxes = $('#activityLogType-grid input[type=checkbox][id!=mastercheckbox]').length;
            var numChkBoxesChecked = $('#activityLogType-grid input[type=checkbox][checked][id!=mastercheckbox]').length;
            $('#mastercheckbox').attr('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
        }
   </script>    
}